<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <title>生态圈系统-开票信息管理</title>
  <link rel="icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">
  <link rel="shortcut icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">

  <!-- CSS  -->
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link href="plugins/bootstrap-4.0.0/css/bootstrap.min.css" th:href="@{/plugins/bootstrap-4.0.0/css/bootstrap.min.css}" type="text/css" rel="stylesheet"/>
  <link href="css/materialize.css" th:href="@{/css/materialize.css}" type="text/css" rel="stylesheet" media="screen,projection"/>
  <link href="plugins/perfect-scrollbar/perfect-scrollbar.css" th:href="@{/plugins/perfect-scrollbar/perfect-scrollbar.css}" type="text/css" rel="stylesheet" media="screen,projection"/>
  <link href="css/style.css" th:href="@{/css/style.css}" type="text/css" rel="stylesheet"/>

  <style>
    input[type="text"]:not(.browser-default) {
      height: 2rem;
    }
    .input-field > label:not(.label-icon).active {
      line-height: 0rem;
    }
    td {
      max-width: 100px;
    }
  </style>
</head>
<body>
  <header>
    <nav class="" role="navigation" style="background-color: #f4f6f9;">
      <div class="nav-wrapper">
        <ul class="right hide-on-med-and-down">
          <!--
          <li><a class="blue-text waves-effect dropdown-trigger" href="#!" data-target="dropdown1" style="vertical-align: top;"><span th:if="${session.user!=null}" th:text="${session.user.username}">admin</span><i class="material-icons right">arrow_drop_down</i></a></li>
           -->
          <li><a class="grey-text waves-effect dropdown-trigger" href="#!" data-target="dropdown1" style="vertical-align: top;"><span sec:authentication="name">admin</span><i class="material-icons right">arrow_drop_down</i></a></li>
          <ul id="dropdown1" class="dropdown-content">
            <li><a href="#modal3" class="waves-effect grey-text modal-trigger">修改密码</a></li>
            <li><a th:href="@{/admin/logout}" class="waves-effect grey-text">退出登录</a></li>
          </ul>
        </ul>

        <a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
      </div>
    </nav>
  </header>

  <div th:replace="common/aside_admin :: aside"></div>

  <main class="" style="height: calc(100% - 48px); background-color: #f4f6f9;">
    <div class="row">
      <h6 style="margin: 0 0 0 15px;" id="page-title" active-menu="invoice-menu">开票信息管理</h6>
    </div>

    <div class="row white" style="margin: 0 15px; height: inherit;">
      <div class="col s12">
	      <table>
	        <thead>
	          <tr style="border-bottom: 0;">
              <th class="no-padding" width="20%"></th>
              <th class="no-padding" width="80%"></th>
	          </tr>
	        </thead>

	        <tbody>
	          <tr>
	            <td class="right">
		            <div class="input-field">发票类型</div>
	            </td>
	            <td>
		            <div class="input-field" style="margin-top: 0; margin-bottom: 0;">
		              <input type="text" name="type" id="type" class="validate" required th:value="${invoice.type}" maxlength="50">
		            </div>
	            </td>
	          </tr>
	          <tr>
	            <td class="right">
	              <div class="input-field">名称</div>
	            </td>
	            <td>
                <div class="input-field" style="margin-top: 0px; margin-bottom: 0px;">
                  <input type="text" name="name" id="name" class="validate" required th:value="${invoice.name}" maxlength="200">
                </div>
              </td>
	          </tr>
	          <tr>
	            <td class="right">
	              <div class="input-field">纳税人识别号</div>
	            </td>
	            <td>
                <div class="input-field" style="margin-top: 0px; margin-bottom: 0px;">
                  <input type="text" name="taxNo" id="taxNo" class="validate" required th:value="${invoice.taxNo}" maxlength="30">
                </div>
              </td>
	          </tr>
	          <tr>
              <td class="right"><div class="input-field">地址、电话</div></td>
              <td>
                <div class="input-field" style="margin-top: 0px; margin-bottom: 0px;">
                  <input type="text" name="addressAndPhone" id="addressAndPhone" class="validate" required th:value="${invoice.addressAndPhone}" maxlength="200">
                </div>
              </td>
            </tr>
            <tr>
              <td class="right">
                <div class="input-field">开户行及账号</div>
              </td>
              <td>
                <div class="input-field" style="margin-top: 0px; margin-bottom: 0px;">
                  <input type="text" name="branchAndAccount" id="branchAndAccount" class="validate" required th:value="${invoice.branchAndAccount}" maxlength="200">
                </div>
              </td>
            </tr>
            <tr>
              <td class="right">
                <div class="input-field">开票项目</div>
              </td>
              <td>
                <div class="input-field" style="margin-top: 0px; margin-bottom: 0px;">
                  <input type="text" name="title" id="title" class="validate" required th:value="${invoice.title}" maxlength="200">
                </div>
              </td>
            </tr>
            <tr>
              <td></td>
              <td>
                <button class="btn waves-effect waves-light light-blue darken-1 right" type="submit" name="action" style="margin-right: 10px;" onclick="updateSubmit()">保存</button>
              </td>
            </tr>
	        </tbody>
	      </table>
      </div>
  	</div>
  </main>

  <!-- <footer class="white page-footer teal">
    <div class="footer-copyright">
      <div class="black-text container">
      Made by <a class="brown-text text-lighten-3" href="http://materializecss.com">Materialize</a>
      </div>
    </div>
  </footer> -->

  <div th:replace="common/update_pwd :: #modal3"></div>

  <!--  Scripts-->
  <script src="js/jquery-3.3.1.min.js" th:src="@{/js/jquery-3.3.1.min.js}"></script>
  <script src="js/materialize.js" th:src="@{/js/materialize.js}"></script>
  <script src="plugins/perfect-scrollbar/perfect-scrollbar.min.js" th:src="@{/plugins/perfect-scrollbar/perfect-scrollbar.min.js}"></script>
  <script src="plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js" th:src="@{/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
  <script src="plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" th:src="@{/plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js}" charset="UTF-8"></script>
  <script src="plugins/bootstrap-sweetalert/sweetalert.min.js" th:src="@{/plugins/bootstrap-sweetalert/sweetalert.min.js}"></script>
  <script src="js/common.js" th:src="@{/js/common.js}"></script>
  <script>
    function updateSubmit() {
    	var input_elems = $('main input');
      input_elems.each(function(){
        M.validate_field($(this));
      });
      var invalid_input_elems = $('main input.invalid');
      console.log(invalid_input_elems.length);
      if(invalid_input_elems.length > 0) {
    	  swal({
          title: "保存失败!",
          text: "请完善信息!",
          icon: "error",
          //timer: 2000,
        });
        return false;
      }
    	$.ajax({
        url: "/kangchenjunga/api/v1/invoice-info/",
        data: '{"type" : "' + $('input[name="type"]').val()
            + '", "name" : "' + $('input[name="name"]').val()
            + '", "taxNo" : "' + $('input[name="taxNo"]').val()
            + '", "addressAndPhone" : "' + $('input[name="addressAndPhone"]').val()
            + '", "branchAndAccount" : "' + $('input[name="branchAndAccount"]').val()
            + '", "title" : "' + $('input[name="title"]').val()
            + '", "id" : 1'
            + '}',
        contentType: "application/json;charset=utf-8",
        type: "PUT",
        headers: {
          Accept: "application/json"
        },
        success: function(data, textStatus) {
          console.log(data);
          swal({
            title: "",
            text: "保存成功!",
            icon: "success",
            timer: 2000,
          }).then(function(value) {
	          $("input[type=reset]").trigger("click");
            window.location.reload();
          });
        },
        error: function (data, textStatus, errorThrown) {
          //console.log(data);
          swal({
            title: "保存失败!",
            text: data.responseJSON.message,
            icon: "error",
            //timer: 2000,
          });
          M.updateTextFields();
        }
      });
    }
  </script>
  </body>
</html>
